package Model.Beans.Results;

import Model.XML.*;
import Model.Beans.*;
import java.util.*;

public class Student_Course implements XMLRequestInterface {
    private Person student;
    private ArrayList courses = new ArrayList();
    private XMLWriter xml = new XMLWriter();
    
    public Student_Course() {}
    
    public void setStudent(Person student)
    {
        this.student = student;
    }
    
    public Person getStudent()
    {
        return student;
    }
    
     public void addCourse(Course course)
    {
        courses.add(course);
    }
    
    public void delCourse(Course course)
    {
        courses.remove(course);
    }
    
    public void addCourse(Course course, int index)
    {
        courses.add(index, course);
    }
    
    public void delCourse(int index)
    {
        courses.remove(index);
    }
    
    public Course getCourse(int index)
    {
        if(index >= 0 && index <= courses.size())
        {
            return (Course)courses.get(index);
        }
        return null;
    }
    
    public ArrayList getCourses()
    {
        return courses;
    }
    
    public void setCourses(ArrayList courses)
    {
        this.courses = courses;
    }
    
    public String toXML()
    {        
        xml.Push("student-course");
        xml.Element("student", student.toString(), Integer.toString(student.getId()));
        
        if(courses.size() > 0)
        {
            String[] attributeName = new String[5];
            String[] attribute = new String[5];
            attributeName[0] = "professor-name";
            attributeName[1] = "time";
            attributeName[2] = "days";
            attributeName[3] = "id";
            attributeName[4] = "classroom";
            for(int i=0; i<courses.size(); i++)
            {
                Course tmp = (Course)courses.get(i);

                attribute[0] = tmp.getProfessor().toString();
                attribute[1] = tmp.getTime();
                attribute[2] = tmp.getDays();
                attribute[3] = Integer.toString(tmp.getId());
                attribute[4] = tmp.getClassRoom().toString();
                
                xml.Element("course", tmp.toString(), attributeName, attribute);  
            }
        }
        else
        {
            xml.Element("course", "no-result");
        }
        //</student_course>
        xml.Pop();
        
        return xml.GetXML();
    }
}
